<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
       //$r=array();
		//$r['username']="管理员";
		//$r['meg']='今天是星期一';
                
		//$this->assign('row',$r);
        $bbsdata=M("think_data");
        $data=$bbsdata->order('id desc')->select();
        $bbscount=$bbsdata->count();
        $this->assign("bbscount",$bbscount);
        $this->assign("rows",$data);
        $this->display();
    }
    public function del(){
        $id=I('get.id',0);
        $bbsdata=M("think_data");
        $rs=$bbsdata->delete($id);
        if ($rs)
        {
            $this->success('删除成功',U('Home/Index/index'));
        }
 else {
    $this->error('删除失败');
}
    }
    
     public function edit(){
         $id=I('get.id',0);
         $model=M("think_data");
         $r=$model->where("id=$id")->find();
         $this->assign("row",$r);
         $this->display();
     }
      public function updata(){
          if(IS_POST)
        {
        $id=I('get.id',0);
        $data['username']=I('post.username','');
        $data['sex']=I('post.sex','男');
        $data['message']=I('post.message','');
        $data['imgurl']=I('post.imgurl','');
        $data['m_data']=data('Y-m-d H:i:s',time());
        $model=M("think_data");
        $model->where("id=$id")->save($data);
       $this->success('修改成功！',U('Home/Index/index'));
        
      } 
       else{
    $this->error('非法操作！');
}
      }    
}